package org.sradon.mySpring.model;

import org.sradon.mySpring.anno.di.Autowired;
import org.sradon.mySpring.anno.di.Value;
import org.sradon.mySpring.context.BeanDefine;
import org.sradon.mySpring.utils.AnnoUtils;

import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;

/**
 * 属性注入执行类
 */
public class DiExecutor {
    public static void ValueLoader(Object bean, Map<String, Object> context, List<BeanDefine> defines){
        // 获取该Bean所有的字段属性
        Field[] fields = bean.getClass().getDeclaredFields();
        for (Field field: fields) {
            if (field.isAnnotationPresent(Value.class)) {
                AnnoUtils.setValue(bean, field);
            }
            if (field.isAnnotationPresent(Autowired.class)) {
                AnnoUtils.putAutowired(bean, field, context, defines);
            }
            if (field.isAnnotationPresent(Resource.class)) {
                AnnoUtils.putResource(bean, field, context, defines);
            }
        }
    }
}
